CONTENTS | INDEX | PREV | NEXT
strcspn
NAME
strcspn - scan a string until a character is found that matches
any character in a second string.
SYNOPSIS
int len = strcspn(s, toks)
const char *s;
const char *toks;
FUNCTION
The string s is scanned until a character is found that matches any
character in the string toks. The number of characters skipped is
returned. If no character in s matches any character in toks then
the length of the string s is returned.
This function is normally used to search for whitespace within a
string. Note that in many cases strpbrk() is more useful than
strcspn().
EXAMPLE
#include <stdio.h>
#include <string.h>
#include <assert.h>
main()
{
int len;
len = strcspn("hello this is a test", " tabcd");
assert(len == 5); /* stopped at the first space */
len = strcspn("hello this is a test", " abl");
assert(len == 2); /* stopped at the first 'l' */
len = strcspn("hello", "abcd");
assert(len == 5); /* stopped at end of string 1 */
return(0);
}
INPUTS
char *s; pointer to string to scan
char *toks; pointer to string containing characters to compare against
RESULTS
int len; # of characters skipped in s before a match was found
SEE ALSO
strpbrk, strspn